package com.cms.web.exportQueryAnalyse;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.metadata.biz.MetaDataServiceMgr;
import com.pub.util.EMPExportExcelTable;
import com.web.BaseController;

import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.dict.DMTServiceMgr;

@Controller
@RequestMapping(value="/queryAnalyse/export")
public class EMPExportCMSKHDAQueryAnalyseController extends BaseController{
	@Autowired
	private                       MetaDataServiceMgr                              MetaDataService;

	@Autowired        
	private                            DMTServiceMgr                                DMTServiceMgr;
	
	@Autowired
	public HttpSession session;

	/**
	 * 生产单剩余数量
	 * @param F_CKBH
	 * @param model
	 * @return
	 */
	@RequestMapping("/KHDAAnalyseQuery")
	public ModelAndView CCTZQueryAnalyse(HttpServletRequest request, HttpServletResponse response, Model model) {
		List<String>  subHeadList = new ArrayList<String>();
		EFDataSet        columnDS = EFDataSet.getInstance();
		EFRowSet         columnRS = null;
		EFDataSet         queryDS = null;
		EFDataSet          metaDS = null;
		try {
			queryDS = DMTServiceMgr.searchDictRow("KHDAZD", "F_KHMC", "", null, 0, 100);
			metaDS = MetaDataService.getSYS_OBJCOLS("KHDAZD");
			for(int i = 0; i < metaDS.getRowCount(); i++) {
				columnRS = EFRowSet.getInstance();
				columnRS.putString("COLUMN_ID", metaDS.getRowSet(i).getString("COL_ID", ""));
				columnRS.putString("COLUMN_ALIGN", "LEFT");
				columnRS.putString("COLUMN_NAME", metaDS.getRowSet(i).getString("COL_MC", ""));
				columnRS.putString("COLUMN_WIDTH", "100");
				columnRS.putString("COLUMN_TYPE", "C");
				columnDS.insertRowSet(columnRS);
			}
			
			//下载
			EMPExportExcelTable exportExcelTable = new EMPExportExcelTable();
			exportExcelTable.exportExcelTable(request, response, queryDS, columnDS, subHeadList, "客 户 档 案 信 息");			
		} catch (Exception e) {

			e.printStackTrace();
		}
		return ajaxDoneError("导出成功！");
	}
}
